<template>
  <a-card>
    <div :class="advanced ? 'search' : null">
      <a-form layout="horizontal">
        <div :class="advanced ? null: 'fold'">
          <a-row >
            <a-col :md="8" :sm="24" >
              <a-form-item
                label="规则编号"
                :labelCol="{span: 5}"
                :wrapperCol="{span: 18, offset: 1}"
              >
                <a-input placeholder="请输入" />
              </a-form-item>
            </a-col>
            <a-col :md="8" :sm="24" >
              <a-form-item
                label="使用状态"
                :labelCol="{span: 5}"
                :wrapperCol="{span: 18, offset: 1}"
              >
                <a-select placeholder="请选择">
                  <a-select-option value="1">关闭</a-select-option>
                  <a-select-option value="2">运行中</a-select-option>
                </a-select>
              </a-form-item>
            </a-col>
            <a-col :md="8" :sm="24" >
              <a-form-item
                label="调用次数"
                :labelCol="{span: 5}"
                :wrapperCol="{span: 18, offset: 1}"
              >
                <a-input-number style="width: 100%" placeholder="请输入" />
              </a-form-item>
            </a-col>
          </a-row>
          <a-row v-if="advanced">
          <a-col :md="8" :sm="24" >
            <a-form-item
              label="更新日期"
              :labelCol="{span: 5}"
              :wrapperCol="{span: 18, offset: 1}"
            >
              <a-date-picker style="width: 100%" placeholder="请输入更新日期" />
            </a-form-item>
          </a-col>
          <a-col :md="8" :sm="24" >
            <a-form-item
              label="使用状态"
              :labelCol="{span: 5}"
              :wrapperCol="{span: 18, offset: 1}"
            >
              <a-select placeholder="请选择">
                <a-select-option value="1">关闭</a-select-option>
                <a-select-option value="2">运行中</a-select-option>
              </a-select>
            </a-form-item>
          </a-col>
          <a-col :md="8" :sm="24" >
            <a-form-item
              label="描述"
              :labelCol="{span: 5}"
              :wrapperCol="{span: 18, offset: 1}"
            >
              <a-input placeholder="请输入" />
            </a-form-item>
          </a-col>
        </a-row>
        </div>
        <span style="float: right; margin-top: 3px;">
          <a-button type="primary">查询</a-button>
          <a-button style="margin-left: 8px">重置</a-button>
          <a @click="toggleAdvanced" style="margin-left: 8px">
            {{advanced ? '收起' : '展开'}}
            <a-icon :type="advanced ? 'up' : 'down'" />
          </a>
        </span>
      </a-form>
    </div>
    <div>
      <a-space class="operator">
        <a-button type="primary" @click="optionMore">批量操作</a-button>
        <a-dropdown>
          <a-menu @click="handleMenuClick" slot="overlay">
            <a-menu-item key="delete">删除</a-menu-item>
            <a-menu-item key="audit">审批</a-menu-item>
          </a-menu>
          <a-button>
            更多操作 <a-icon type="down" />
          </a-button>
        </a-dropdown>
      </a-space>
      <standard-table
        ref="table"
        bordered
        :isShowCheckBox="true"
        :isPagination="true"
        :columns="columns"
        :dataSource="dataSource"
        @onSelectChange="onSelectChange"
      >
        <template slot="action" slot-scope="{text, record}">
          <a @click="deleteRecord(record.id)">
            <a-icon type="delete" />删除
          </a>
        </template>
      </standard-table>  
    </div>
  </a-card>
</template>

<script>
import StandardTable from '@/components/table/StandardTable'
import {request, METHOD} from '@/utils/request'
export default {
  name: 'query',
  components: {StandardTable},
  data () {
    return {
      advanced: true,
      dataSource: [{
          key: 0,
          id:'111',
          date: '2022-02-11',
          amount: 120,
          type: 'income',
          note: 'transfer'
        },
        {
          key: 1,
          id:'222',
          date: '2018-03-11',
          amount: 243,
          type: 'income',
          note: 'tranwsfertransfertransfertransfertransfertransfertransfertransfertransfertransfertransfertransfertransfertransfertransfer'
        },
        {
          key: 2,
          id:'333',
          date: '2018-04-11',
          amount: 98,
          type: 'income',
          note: 'tranqsfer'
      }],
      columns: [{
          title: 'Date',
          dataIndex: 'date',
          width: 200,
          fieldType: 'Date',
          dataType: 'String',
          scopedSlots: {
            filterDropdown: "filterDropdown",
            filterIcon: "filterIcon",
            customRender: "date"
          },
        },{
          title: 'Note',
          dataIndex: 'note',
          width: 200,
          fieldType:'Input',
          dataType: "String",
          scopedSlots: {
            filterDropdown: "filterDropdown",
            filterIcon: "filterIcon",
            customRender: "note"
          },
        },{
          title: 'Amount',
          dataIndex: 'amount',
          width: 100,
          fieldType:'Input',
          dataType: "Number",
          scopedSlots: {
            filterDropdown: "filterDropdown",
            filterIcon: "filterIcon",
            customRender: "amount"
          },
        },{
          title: 'Type',
          dataIndex: 'type',
          width: 100,
          scopedSlots: { customRender: 'type' }
        },{
          title: 'Action',
          key: 'action',
          scopedSlots: { customRender: 'action' }
      }],
      selectedRows: []
    }
  },
  mounted(){
    request('/api/v1/2/personal-configs/user', METHOD.get,{}).then(res => {
      console.log(194,res.data)
    })
  },
  methods: {
    //收起展开
    toggleAdvanced () {
      this.advanced = !this.advanced
    },
    //批量操作
    optionMore(){
      console.log(this.selectedRows)
    },
    //更多操作
    handleMenuClick (e) {
      console.log(e.key)
    },
    //表格选中项
    onSelectChange(id,row){
      this.selectedRows = row
      console.log(id,row)
    },
    //表格删除
    deleteRecord(id) {
      this.dataSource = this.dataSource.filter(item => item.id !== id)
    },
  }
}
</script>

<style lang="less" scoped>
  .search{
    margin-bottom: 54px;
  }
  .fold{
    width: calc(100% - 216px);
    display: inline-block
  }
  .operator{
    margin-bottom: 18px;
  }
  @media screen and (max-width: 900px) {
    .fold {
      width: 100%;
    }
  }
</style>
